package com.guodexian.xiaomi;

import com.guodexian.xiaomi.service.CategoryService;
import com.guodexian.xiaomi.service.impl.CategoryServiceImpl;
import com.guodexian.xiaomi.util.HttpResponseUtil;
import com.guodexian.xiaomi.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 类说明：  <br>
 *
 * @author 南阳德刚<br>
 * 2024-12-31 11:23<br>
 * @since 1.0 <br>
 * 培养IT高薪技术人才的摇篮---北京学佳澳。<br>
 * 点击<a href="http://www.xuejiaao.com/images/qrcode.jpg">学佳澳教育</a>关注公共号,有惊喜(⊙o⊙)<br>
 */
@WebServlet("/category/del/all")
public class CategoryBatchDelController extends HttpServlet {
    private CategoryService categoryService=new CategoryServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取参数
        String[] strCids= request.getParameterValues("cid[]");
        if(strCids==null||strCids.length==0){
            HttpResponseUtil.response(response, ResultVO.fail("没有传递id"));
            return;
        }
        Long[] cis=new Long[strCids.length];
        for(int i=0;i<strCids.length;i++){
            cis[i]=Long.parseLong(strCids[i]);
        }
        int ret=categoryService.deleteCategoryByIds(cis);
        if(ret>0){
            HttpResponseUtil.response(response,ResultVO.success(ret));
        }else {
            HttpResponseUtil.response(response,ResultVO.fail("删除失败"));
        }
    }
}